<?php

require_once(APPLICATION_PATH.'/models/Items.php');
require_once(APPLICATION_PATH.'/models/VotedIps.php');
require_once(APPLICATION_PATH.'/models/FilterIps.php');
require_once('BaseController.php');

class AdminController extends BaseController
{
    
    public function indexAction()
    {
        $this->render('index');
    }
    
    //添加选项
    public function additemAction()
    {
        $request = $this->getRequest();

        if($request->isPost())
        {
            $itemName = $request->getParam('item_name');
            $itemDesc = $request->getParam('item_desc');
            $counts = $request->getParam('counts');

            $item = new Items();
            $data = array(
                'name' => $itemName,
                'description' => $itemDesc,
                'counts' => $counts
            );
            //Zend_Debug::dump($data);
            $item->insert($data);
        }
        else
        {
            $this->render('additem');
        }
    }
   
    //添加要过滤掉的ip
    public function addfilterAction()
    {
        $request = $this->getRequest();
        
        if($request->isPost())
        {
            $ipAddress = $request->getParam('ip_address');
            
            $filterIp = new FilterIps();
            
            $data = array(
                'ip' => $ipAddress
            );
            
            $filterIp->insert($data);
            //Zend_Debug::dump($filterIp->insert($data));
            $this->render('index');
        }
        else
        {
            $this->render('addfilter');
        }
    }
}
